#version 330 core
layout (location = 0) in vec3 aPos;
layout (location = 1) in vec3 aInstancePos;   // 实例位置
layout (location = 2) in vec3 aInstanceColor; // 实例颜色
layout (location = 3) in float aInstanceRadius; // 实例半径

uniform mat4 projection;
uniform mat4 view;

out vec3 vInstanceColor;
out vec3 vInstancePos;

void main()
{
    // 手动构建模型矩阵（平移 + 缩放）
    mat4 model = mat4(1.0);
    
    // 平移矩阵
    model[3].xyz = aInstancePos; // 直接设置平移分量
    
    // 缩放矩阵（均匀缩放）
    model[0][0] = aInstanceRadius;
    model[1][1] = aInstanceRadius;
    model[2][2] = aInstanceRadius;
    
    // 组合最终顶点位置
    gl_Position = projection * view * model * vec4(aPos, 1.0);

    vInstanceColor = aInstanceColor;
    vInstancePos = aInstancePos;
}